# -*- encoding: utf-8 -*-  
  
import urllib2  
from weixin.api.common import getAccToken
  
  
def crtMenu():
    access_token=getAccToken()
    # print access_token  cd ..
    posturl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token  
    print posturl
    
    menu = '''{
         "button":[
#          {    
#               "type":"view",
#               "name":"吃",
#               "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8b3baab22e99e996&redirect_uri=http%3a%2f%2fdingcan.team4.us&response_type=code&scope=snsapi_base&state=123#wechat_redirect"
#          },
            {    
             "type":"click",
             "name":"吃",
             "key":"V1001_EAT"
            },
#           {
#                "type":"click",
#                "name":"玩",
#                "key":"V1001_PLAY"
#           },
          {
               "name":"我的",
               "sub_button":[
               {
                   "type":"click",
                   "name":"个人中心",
                   "key":"V1002_CUSTOMCENTER"
                },
                {
                   "type":"click",
                   "name":"关于我们",
                   "key":"V1003_ABOUTUS"
                }]
           }]
     }'''  
      
      
#     req=urllib2.urlopen(posturl, menu.encode('utf-8'))  
    req=urllib2.urlopen(posturl, menu.encode('utf-8'))  
      
    print req.read()  


crtMenu()
# tmploc=userlocation.objects.filter(userid="公司")[0]
# taglat=tmploc.latitude
# taglng=tmploc.longitude
# print getDTurl("11","11","11","11")
# sendCSMess('oqRfwjhgztG3BTSBPvSYj2-KuPOg',getDTurl("11","11",taglat,taglat))
# userloc=userlocation.objects.filter(userid='oqRfwjhgztG3BTSBPvSYj2-KuPOg')
# print userloc[0].infotime[:8]
# for tmouloc in userloc:
#     print tmouloc.userid